#!/usr/bin/make -f
#
# Jailhouse, a Linux-based partitioning hypervisor
#
# Copyright (c) Siemens AG, 2019
#
# Authors:
#  Jan Kiszka <jan.kiszka@siemens.com>
#
# SPDX-License-Identifier: MIT
#

ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
SET_CROSS_BUILD_TOOLS=CROSS_BUILD_TOOLS=y
endif

PARALLEL_BUILD=-j $(shell echo $$(($$(nproc) * 2)))

override_dh_auto_build:
	echo "CONFIG_BOOTCOMMAND=\"setenv fdtfile xilinx/avnet-ultra96-rev$(ULTRA96_VERSION).dtb; run distro_bootcmd\"" \
	    >> configs/${U_BOOT_CONFIG}
	echo "CONFIG_WATCHDOG=n" >> configs/${U_BOOT_CONFIG}
	echo "CONFIG_WDT=n" >> configs/${U_BOOT_CONFIG}
	$(MAKE) $(PARALLEL_BUILD) $(U_BOOT_CONFIG)
	$(MAKE) $(PARALLEL_BUILD) ${U_BOOT_BIN} tools

	tools/mkimage -T zynqmpbif -d ../ultra96.bif boot.bin

	$(MAKE) $(PARALLEL_BUILD) $(SET_CROSS_BUILD_TOOLS) NO_SDL=1 tools-only envtools

override_dh_auto_install:
	mv tools/env/lib.a tools/env/libubootenv.a

override_dh_auto_test:

%:
	CFLAGS= LDFLAGS= dh $@ --parallel
